home *** CD-ROM | disk | FTP | other *** search
- Path: damon.irf.uni.dortmund.de!broth
- From: rothert@damon.irf.uni-dortmund.de (Bernd Rothert)
- Newsgroups: comp.lang.c++
- Subject: Re: BORLAND C++ 4.5 wont add .1 and .9
- Date: Fri, 26 Jan 96 11:47:09 GMT
- Organization: Institute of Robotics Research
- Message-ID: <4eaf69$4oj@damon.irf.uni-dortmund.de>
- References: <corekinDLG8t4.3C5@netcom.com> <4e5njv$e9v@damon.irf.uni-dortmund.de> <4e8e80$jdc@linet02.li.net>
- NNTP-Posting-Host: broth.irf
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- In article <4e8e80$jdc@linet02.li.net>, bsilvern@li.net (Bob Silvern) wrote:
- >>#include <stdio.h>
- >>int one(void) { return 1; }
- >>int main(void)
- >>{
- >> int zero = 0;
- >> int two = (zero == 0) ? one()+1 : zero+1;
- >> printf("one() plus 1 is %d\n", two);
- >> return 0;
- >>}
- >> one() plus 1 is 1
- >above code on Borland 4.02 and it worked correctly. I'm curious what the
- >problem really is. Is it a problem with the ? operator within the definition
- >of the variable "two"? Is it calling the function one() from within the
- >definition of "two". Is it a printf bug? None of these seems likely.
-
- It's the ? operator as you can see in the assembler source (bcc -B onetwo.c):
- ---- cut
- _main proc near
- enter 2,0
- push si
- xor si,si
- or si,si
- jne short @2@86
- call near ptr @one$qv ;<-call one(), result in AX but
- jmp short @2@114 ;<-no inc/add
- @2@86:
- lea ax,word ptr [si+1] ;<- : zero+1
- @2@114:
- mov word ptr [bp-2],ax
- push word ptr [bp-2]
- push offset DGROUP:s@
- call near ptr _printf
- add sp,4
- xor ax,ax
- ---- cut
-
- Bernd
-